class Solution
{
public:
    long long minCost(vector<int> &nums, int x)
    {
        long long minCost = LONG_LONG_MAX;
        vector<int> minCostEachPos = nums;
        int n = nums.size();
        for (long long i = 0; i < n; ++i)
        {
            long long cost = i * x;
            for (int j = 0; j < n; ++j)
            {
                minCostEachPos[j] = min(minCostEachPos[j], nums[(j + i) % n]);
                cost += minCostEachPos[j];
            }
            minCost = min(minCost, cost);
        }
        return minCost;
    }
};